import { Router } from 'express';
import { QuestionController } from '../controllers/question-controller';
import { authMiddleware } from '../middleware/auth'; // 导入auth中间件

const router: Router = Router();

// 问题管理路由

// 获取问题列表（支持分页、筛选、搜索）
router.get('/list', authMiddleware, QuestionController.getQuestions);

// 获取问题详情
router.get('/:id', authMiddleware, QuestionController.getQuestionById);

// 创建问题
router.post('/', authMiddleware, QuestionController.createQuestion);

// 更新问题
router.put('/:id', authMiddleware, QuestionController.updateQuestion);

// 删除问题
router.delete('/:id', authMiddleware, QuestionController.deleteQuestion);

// 点赞问题
router.post('/:id/like', authMiddleware, QuestionController.likeQuestion);

// 取消点赞问题
router.delete('/:id/like', authMiddleware, QuestionController.unlikeQuestion);

// 获取用户的问题列表
router.get(
  '/user/:userId',
  authMiddleware,
  QuestionController.getUserQuestions
);

// 获取热门问题
router.get(
  '/popular/list',
  authMiddleware,
  QuestionController.getPopularQuestions
);

// 获取最新问题
router.get(
  '/latest/list',
  authMiddleware,
  QuestionController.getLatestQuestions
);

export default router;
